import { _decorator, Component, Animation, Toggle, Node } from 'cc';
import { AudioManager } from './AudioManager';
import { Config } from './Config';
import { SDKManager } from './SDKManager';
const { ccclass, property } = _decorator;

@ccclass('msgUISet')
export class msgUISet extends Component {

    @property(AudioManager)
    public audionManager: AudioManager = null!

    @property(Animation)
    public anim: Animation = null!;

    @property(Toggle)
    public btnMusic: Toggle = null!;
    @property(Toggle)
    public btnSound: Toggle = null!;
    @property(Toggle)
    public btnShock: Toggle = null!;

    @property(Node)
    public mask: Node = null!;

    start() {
        this.mask.setScale(1, Config.heightScaling)
        this.btnMusic.isChecked = this.audionManager.getIsMusic()
        this.btnSound.isChecked = this.audionManager.getIsSound()
        this.btnShock.isChecked = this.audionManager.getIsShock()
    }

    show() {
        this.node.active = true
        this.anim?.play('pop-up');
        this.audionManager.playSound()
        SDKManager.showCustomAd('bottom')
    }

    hide() {
        this.anim?.play('pop-out');
        this.anim.on(Animation.EventType.STOP, this.onAnimationStop, this);
        this.audionManager.playSound()
        SDKManager.hideCustomAd()
    }

    // onBtnClose() {
    //     //反向播放动画
    //     let state = this.animation.getState('pop-up')
    //     state.wrapMode = AnimationClip.WrapMode.Reverse
    //     this.animation.play('pop-up');
    //     this.animation.on(Animation.EventType.STOP, this.onAnimationStop, this);
    // }

    onAnimationStop() {
        this.node.active = false;
        this.anim.off(Animation.EventType.STOP, this.onAnimationStop, this);
        //director.getScene().emit('destroy msg')
    }

    onBtnMusic() {
        this.audionManager.setIsMusic(this.btnMusic.isChecked)
        this.audionManager.playSound()
    }
    onBtnSound() {
        this.audionManager.setIsSound(this.btnSound.isChecked)
        this.audionManager.playSound()
    }

    onBtnShock() {
        this.audionManager.setIsShock(this.btnShock.isChecked)
        this.audionManager.playSound()
    }

}
